﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EventManager.Resolver;
using Autofac;
using Autofac.Integration.Mvc;
using EventManager.Model.Entites;
using EventManager.Model.Factory;

namespace EventManager
{
    public static class Bootstraper
    {
        public static void Run()
        {
            ConfigureContainer();
            CreateBaseCategories();
        }

        private static void CreateBaseCategories()
        { 
            var categories = new List<Categories>
            {
                new Categories { Id = Guid.NewGuid(), Name = "Szkoła", Description = string.Empty },
                new Categories { Id = Guid.NewGuid(), Name = "Imprezy", Description= string.Empty },
                new Categories { Id = Guid.NewGuid(), Name = "Czas wolny", Description= string.Empty }
            };

            using (var context = new EMDbContext())
            {
                if (!context.Categories.Any())
                {
                    foreach (var cat in categories)
                    {
                        context.Categories.Add(cat);
                    }

                    context.SaveChanges(); 
                }
            }
        }

        private static void ConfigureContainer()
        {
            var container = IocConfig.Resolve<MvcApplication>();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
    }
}